﻿<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	xmlns:ViewModel1="clr-namespace:SfdClient.ViewModel"
    xmlns:Converters="clr-namespace:SfdClient.Converter"
    xmlns:GalaSoft_MvvmLight_Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF4"
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
    x:Class="SfdClient.View.AzureProjectsView"
    mc:Ignorable="d"
    d:DesignWidth="640" 
    d:DesignHeight="480">

<UserControl.Resources>
        <Converters:SyncMasterToImageConverter x:Key="syncToImageConverter"/>
        <Converters:BoolToVisibilityConverter x:Key="boolToVisibilityConverter"/>
        <Style x:Key="ImageStyle1" TargetType="{x:Type Image}">
			<Style.Triggers>
				<DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}, Mode=FindAncestor}}" Value="True">
					<Setter Property="Visibility" Value="Visible"/>
				</DataTrigger>
				<DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}, Mode=FindAncestor}}" Value="False">
					<Setter Property="Visibility" Value="Collapsed"/>
				</DataTrigger>
			</Style.Triggers>
		</Style>
		<Style x:Key="ListBoxItemStyle1" TargetType="{x:Type ListBoxItem}">
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate TargetType="{x:Type ListBoxItem}">
						<Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
							<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
						</Border>
						
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>
</UserControl.Resources>
	<UserControl.DataContext>
		<Binding Path="AzureProjectsViewModel" Source="{StaticResource locator}"/>
	</UserControl.DataContext>
    <Grid Background="{DynamicResource mainBackgroundBrush}" >
    	<VisualStateManager.VisualStateGroups>
    		<VisualStateGroup x:Name="VisualStateGroup">
    			<VisualStateGroup.Transitions>
    				<VisualTransition From="Expanded" GeneratedDuration="0:0:0.5" To="Collapsed">
    					<VisualTransition.GeneratedEasingFunction>
    						<ExponentialEase EasingMode="EaseIn"/>
    					</VisualTransition.GeneratedEasingFunction>
    				</VisualTransition>
    				<VisualTransition From="Collapsed" GeneratedDuration="0:0:0.2" To="Expanded">
    					<VisualTransition.GeneratedEasingFunction>
    						<ExponentialEase EasingMode="EaseIn"/>
    					</VisualTransition.GeneratedEasingFunction>
    					<Storyboard>
    						<DoubleAnimation Duration="0:0:0.2" To="1" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="grid">
    							<DoubleAnimation.EasingFunction>
    								<ExponentialEase EasingMode="EaseIn"/>
    							</DoubleAnimation.EasingFunction>
    						</DoubleAnimation>
    					</Storyboard>
    				</VisualTransition>
    			</VisualStateGroup.Transitions>
    			<VisualState x:Name="Collapsed"/>
    			<VisualState x:Name="Expanded">
    				<Storyboard>
    					<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="border">
    						<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
    					</DoubleAnimationUsingKeyFrames>
    					<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="grid">
    						<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
    					</DoubleAnimationUsingKeyFrames>
    				</Storyboard>
    			</VisualState>
    		</VisualStateGroup>
    	</VisualStateManager.VisualStateGroups>
    	<Grid.RowDefinitions>
    		<RowDefinition Height="Auto"/>
    		<RowDefinition Height="*"/>
    		<RowDefinition Height="Auto"/>
    	</Grid.RowDefinitions>
    	    	<Grid Height="64">
    		<Grid.ColumnDefinitions>
    			<ColumnDefinition Width="64"/>
    			<ColumnDefinition Width="*"/>
    		</Grid.ColumnDefinitions>
    		<Image Source="{DynamicResource AppIcon}" />
            <TextBlock Style="{DynamicResource TitleStyle}" Grid.Column="1" Text="{Binding [AzureProjectsView_Titre], Source={StaticResource localizer}}"/>
    	</Grid>
    	<ListBox 
								SelectedItem="{Binding SelectedProject}" 
								ItemsSource="{Binding Projects}" 
								ItemTemplate="{DynamicResource clmAzure}" 
								ItemContainerStyle="{DynamicResource ListBoxItemStyle1}" 
								ScrollViewer.VerticalScrollBarVisibility="Disabled" Grid.Row="1" Background="{x:Null}" BorderBrush="{x:Null}" >
    	
                                <ListBox.Resources>
                                    
                                	<DataTemplate x:Key="clmAzure" DataType="{x:Type ViewModel1:AzureSyncProjectViewModel}">
                                		<Border Width="300" Height="160" Padding="10" Background="#FF76ABFF" Margin="8,8,0,0">
                                			<Grid >
                                                <!--Infos sur le projet-->
                                				<Grid d:LayoutOverrides="Width">
                                					<Grid.RowDefinitions>
                                						<RowDefinition Height="Auto"/>
                                						<RowDefinition Height="*"/>
                                						<RowDefinition Height="Auto"/>
                                						<RowDefinition Height="Auto"/>
                                					</Grid.RowDefinitions>
                                					<TextBlock TextWrapping="Wrap" FontSize="16" Foreground="White" Text="{Binding FriendlyName}" VerticalAlignment="Stretch" d:LayoutOverrides="Height" />
                                <Image 
                                    Source="{Binding Master, Converter={StaticResource syncToImageConverter}}" 
                                    HorizontalAlignment="Left" Grid.Row="1" VerticalAlignment="Center" Height="48" />
                                
								<Image x:Name="imgDelete" 
                                       HorizontalAlignment="Right" 
                                       Source="{DynamicResource Delete32}" Width="48" VerticalAlignment="Center" Grid.Row="1" Height="48"
                                       Visibility="{Binding Delete, Converter={StaticResource ResourceKey=boolToVisibilityConverter}}"/>
                                <TextBlock TextWrapping="Wrap" FontSize="10" Foreground="White" Text="{Binding ContainerName}" d:LayoutOverrides="Height" Grid.Row="2" />
                                <TextBlock TextWrapping="NoWrap" FontSize="10" Foreground="White" Text="{Binding LocalFolder}" TextTrimming="CharacterEllipsis" Grid.Row="3" ToolTip="{Binding LocalFolder}" />
                                				</Grid>
											
                                                <!---Affichage de la progression lors d'une synchro-->
                                				<Grid Grid.Row="0"  HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,-8,-8">
                                					<Grid.Style>
                                						<Style>
                                							<Style.Triggers>
                                								<DataTrigger Binding="{Binding IsWorking}" Value="True">
                                									<Setter Property="UIElement.Visibility" Value="Visible" />
                                								</DataTrigger>

                                								<DataTrigger Binding="{Binding IsWorking}" Value="False">
                                									<Setter Property="UIElement.Visibility" Value="Collapsed" />
                                								</DataTrigger>
                                							</Style.Triggers>
                                						</Style>
                                					</Grid.Style>
                                					<ProgressBar Value="{Binding SyncProgress, Mode=OneWay}" Style="{DynamicResource ProgressBarBusyIndicator}" IsIndeterminate="True" Width="70" Height="70" />
                                					<TextBlock  TextWrapping="Wrap" Text="{Binding SyncProgress, Mode=OneWay, StringFormat=\{0\}%}" d:LayoutOverrides="Width, Height" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="9.333" Foreground="{DynamicResource TitleFontBrush}"/>
                                				</Grid>
                                                <!--Icône indiquant que l'item est sélectionné-->
                                				<Image 
                                					x:Name="imgIsSelected"
                                					Source="{DynamicResource Check}" 
                                					Width="{DynamicResource ListViewImageWidth}" 
                                					Height="{DynamicResource ListViewImageHeight}" 
                                					VerticalAlignment="Top" 
                                					HorizontalAlignment="Right" Grid.Column="0" Style="{DynamicResource ImageStyle1}" d:LayoutOverrides="GridBox" Margin="0,-10,-10,0" />
                                			</Grid>
                                		</Border>
                                		<DataTemplate.Triggers>
                                			<Trigger Property="ContentControl.Content" Value="{x:Null}"/>
                                		</DataTemplate.Triggers>
                                	</DataTemplate>
                                </ListBox.Resources>
    	
			<ListBox.ItemsPanel>
    			<ItemsPanelTemplate>
    				<WrapPanel IsItemsHost="True" Orientation="Vertical"/>
				</ItemsPanelTemplate> 		
			</ListBox.ItemsPanel>
    		<i:Interaction.Triggers>
    			<i:EventTrigger EventName="MouseDoubleClick">
    				<GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding NavigateToExplorerCommand, Mode=OneWay}"/>
    			</i:EventTrigger>
    		</i:Interaction.Triggers>
            </ListBox>
        <!--La toolbar-->
    	<Border x:Name="border" Grid.Row="2" Background="Black" d:LayoutOverrides="Height">
    		<Grid x:Name="grid" Background="Black" Opacity="1" >
    			<Grid.ColumnDefinitions>
    				<ColumnDefinition Width="Auto"/>
    				<ColumnDefinition Width="Auto"/>
    				<ColumnDefinition Width="*"/>
    				<ColumnDefinition Width="Auto"/>
    				<ColumnDefinition Width="Auto"/>
    			</Grid.ColumnDefinitions>
				
                <!--Section gauche-->
    			<StackPanel d:LayoutOverrides="Height" Orientation="Horizontal">
    				<Button x:Name="btnSync" Style="{DynamicResource Win8ButtonStyle}" Command="{Binding SynchronizeCommand}" >
    					<StackPanel Orientation="Vertical">
    						<Image Source="{DynamicResource Refresh}" Height="48"/>
                            <TextBlock TextWrapping="Wrap" Foreground="White" Text="{Binding [AzureProjectsView_Synchroniser], Source={StaticResource localizer}}" HorizontalAlignment="Center"/>
    					</StackPanel>
    				</Button>
                    <Button x:Name="btnCancel" Style="{DynamicResource Win8ButtonStyle}" Command="{Binding CancelCommand}" >
                        <StackPanel Orientation="Vertical">
                            <Image Source="{DynamicResource Cancel}" Height="48"/>
                            <TextBlock TextWrapping="Wrap" Foreground="White" Text="{Binding [AzureProjectsView_Annuler], Source={StaticResource localizer}}" HorizontalAlignment="Center"/>
                        </StackPanel>
                    </Button>
                    
                    <Button x:Name="btnExplore" Style="{DynamicResource Win8ButtonStyle}" IsEnabled="True" Command="{Binding NavigateToExplorerCommand}" >
    					<StackPanel Orientation="Vertical">
    						<Image Source="{DynamicResource Explore}" Height="48"/>
                            <TextBlock TextWrapping="Wrap" Foreground="White" Text="{Binding [AzureProjectsView_Comparer], Source={StaticResource localizer}}" HorizontalAlignment="Center"/>
    					</StackPanel>
    				</Button>

                    <Button x:Name="btnNavigate" Style="{DynamicResource Win8ButtonStyle}" IsEnabled="True" Command="{Binding NavigateToUrlCommand}" >
                        <StackPanel Orientation="Vertical">
                            <Image Source="{DynamicResource WindowsAzure}" Height="48"/>
                            <TextBlock TextWrapping="Wrap" Foreground="White" Text="{Binding [AzureProjectsView_WindowsAzure], Source={StaticResource localizer}}" HorizontalAlignment="Center"/>
                        </StackPanel>
                    </Button>

                    <Button x:Name="btnNavigateToSettings" Style="{DynamicResource Win8ButtonStyle}" IsEnabled="True" Command="{Binding NavigateToSettingsCommand}" >
                        <StackPanel Orientation="Vertical">
                            <Image Source="{DynamicResource WindowsAzure}" Height="48"/>
                            <TextBlock TextWrapping="Wrap" Foreground="White" Text="{Binding [AzureProjectsView_Parametres], Source={StaticResource localizer}}" HorizontalAlignment="Center"/>
                        </StackPanel>
                    </Button>

                </StackPanel>
                
                <!--Section droite-->
    			<StackPanel Grid.Column="3" Orientation="Horizontal" d:LayoutOverrides="Width">
                    <Button x:Name="btnAdd" Style="{DynamicResource Win8ButtonStyle}" Command="{Binding AddProjectCommand}" >
    					<StackPanel Orientation="Vertical">
    						<Image Source="{DynamicResource Plus}" Height="48"/>
                            <TextBlock TextWrapping="Wrap" Foreground="White" Text="{Binding [AzureProjectsView_Ajouter], Source={StaticResource localizer}}" HorizontalAlignment="Center"/>
    					</StackPanel>
    				</Button>

    				<Button x:Name="btnEdit" Style="{DynamicResource Win8ButtonStyle}" IsEnabled="True" Command="{Binding EditProjectCommand}">
    					<StackPanel Orientation="Vertical">
    						<Image Source="{DynamicResource Edit}" Height="48"/>
                            <TextBlock TextWrapping="Wrap" Foreground="White" Text="{Binding [AzureProjectsView_Editer], Source={StaticResource localizer}}" HorizontalAlignment="Center"/>
    					</StackPanel>
    				</Button>

                    <Button x:Name="btnDelete" Style="{DynamicResource Win8ButtonStyle}" Command="{Binding DeleteProjectCommand}" >
    					<StackPanel Orientation="Vertical">
    						<Image Source="{DynamicResource Delete}" Height="48"/>
                            <TextBlock TextWrapping="Wrap" Foreground="White" Text="{Binding [AzureProjectsView_Supprimer], Source={StaticResource localizer}}" HorizontalAlignment="Center"/>
    					</StackPanel>
    				</Button>
    			</StackPanel>
    		</Grid>
    	</Border>
    </Grid>
</UserControl>
